#include<iostream>
#include<string>
using namespace std;
string a[15];
string b[15];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin.ignore();
        getline(cin, a[i]);
        int pos = 0;
        while (pos < a[i].size())
        {
            pos = a[i].find(' ', pos + 1);
            while (a[i][pos + 1] == ' ') a[i] = a[i].erase(pos);
            if (!isalpha(a[i][pos + 1]))
            {
                if (a[i][pos + 1] == '?') a[i][pos + 1] = '!';
                a[i].erase(pos);
            }
        }
        b[i] = a[i];
    }
    for (int i = 1; i <= n; i++) cout << a[i] << endl << "AI: " << b[i] << endl;
    return 0;
}